package ru.len.cafe.ejb.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import ru.len.cafe.entity.model.CafeOrder;
import ru.len.cafe.entity.model.Dish;

/**
 * 
 * @author Stanislav Chetvertkov
 *
 */
@Stateless
public class OrderDao {

    @PersistenceContext(unitName = "LenCafePU")
    EntityManager em;

    /**
     * 
     * @param order
     */
    public void createOrder(CafeOrder order){
	em.persist(order);
    }
    
    /**
     * 
     * @param order
     */
    public void deleteOrder(CafeOrder order){
	em.remove(order);
    }
    
    /**
     * 
     * @param order
     */
    public void updateOrder(CafeOrder order){
	em.refresh(order);
    }
    
    /**
     * 
     * @param order
     * @param dish
     */
    public void addDish(CafeOrder order, Dish dish){
	order.getDishes().add(dish);
	updateOrder(order);
    }
    
}